<template>
	<view>
		<view class="background"></view>
		<view class="map">
		
		</view>
		<view class=service>
			<view class="serviceTag">
				<view class="tagItem" v-for="(item,index) in serviceTag" :key="index"
				:class="current==index?'choice':''"
				@click="changeCurrent" :data-index="index"
				>
					{{ item.name }}
				</view>
			</view>
			<swiper :style="'height:'+swiperHeight+'rpx'" :current="current" @change="getCurrent">
				<swiper-item v-for="(item,index) in serviceTag" :key="index">
					<view :id="'start'+index" />
					<form class="form" @submit="onSubmit">
						<view class="input" v-if="(item.name != '拖车')">
							<view class="tag">
								位置
							</view>
							<input v-model="position" name="startAdd" type="text" placeholder="请输入位置"/>
						</view>
						<view class="input" v-if="(item.name == '拖车')">
							<view class="tag">
								起点
							</view>
							<input name="startAdd" type="text" placeholder="请输入位置"/>
						</view>
						<view class="input" v-if="(item.name == '拖车')">
							<view class="tag">
								终点
							</view>
							<input name="endAdd" type="text" placeholder="请输入位置"/>
						</view>
						<view class="input" >
							<view class="tag">
								求助人
							</view>
							<input name="name" type="text" placeholder="请输入姓名"/>
						</view>
						<view class="input" >
							<view class="tag">
								联系方式
							</view>
							<input name="phone" type="text" placeholder="请输入手机号"/>
						</view>
						<view class="input" v-if="(item.name == '拖车')">
							<view class="tag">
								车辆类型
							</view>
							<picker mode="selector" :range="array" @change="bindPickerChange">
								<view class="picker">
									{{ array[arrayIndex] }}
								</view> 	
							</picker>
						</view>
						<view class="input" >
							<view class="tag">
								车牌
							</view>
							<input name="carCode" type="text" placeholder="请输入车牌"/>
						</view>
						<view class="input" >
							<view style="margin-top: -150rpx;" class="tag">
								描述
							</view>
							<textarea class="textarea" name="description" id="" cols="30" rows="10" placeholder="请描述详细信息"></textarea>
						</view>
						<button class="btn" form-type="submit">呼叫救援</button>
						<navigator class="ToRecord" url="/packagesRescue/record/record">
							<view class="">救援记录</view>
							<view class="arrow"></view>
						</navigator>
					</form>
					<view :id ="'end'+index" />
				</swiper-item>
			</swiper>
		</view>
		<view class="Policeervice">
			<view class="title">
				警务救助
			</view>
			<view class="body">
				<view class="">
					<img class="icon" src="/static/交通事故 拷贝@2x.png" alt="" />
					<view>交通事故</view>
					<view>122</view>
				</view>
				<view class="">
					<img class="icon" src="/static/火警@2x.png" alt="" />
					<view>火警</view>
					<view>119</view>
				</view>
				<view class="">
					<img class="icon" src="/static/急救包@2x.png" alt="" />
					<view>急救中心</view>
					<view>120</view>
				</view>
				<view class="">
					<img class="icon" src="/static/警察,公安@2x.png" alt="" />
					<view>公安报警</view>
					<view>110</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				serviceTag: '',
				infoTag: ['位置','求助人','联系方式','车牌','描述'],
				current: 0,
				swiperHeight: 0,
				array: ['小轿车','SUV','七座以上','越野车','跑车','房车'],
				arrayIndex: 0,
				loginUser: '',
				position:'',
				// formData:{
				// 	typeId: this.current + 1,
				// 	position:'',
				// 	end:'',
				// 	userName:'',
				// 	phone:'',
				// 	carType: this.array[this.arrayIndex],
				// 	carNum:'',
				// 	description:'',
					
				// },
			}
		},
		methods: {
			// picker选择
			bindPickerChange(e){
				this.arrayIndex = e.detail.value
				console.log(e.detail.value)
			},
			// 获取表单数据
			onSubmit(e){
				console.log()
				let rescueTask = {
					uid: this.loginUser.id,
					typeId: this.current + 1,
					position: e.detail.value.startAdd,
					end: e.detail.value.endAdd,
					userName: e.detail.value.name,
					phone: e.detail.value.phone,
					carType: this.array[this.arrayIndex],
					carNum: e.detail.value.carCode,
					description: e.detail.value.description	
				}
				let param = JSON.stringify(rescueTask)
				uni.navigateTo({
					url: `../waitRescue/waitRescue?rescueTask=${param}`
				})
				
			},
			// 获取、更改swiper页面
			getCurrent(e){
				this.current = e.detail.current
				this.getHeight()
			},
			changeCurrent(e){		
				this.current = e.currentTarget.dataset.index
				this.getHeight()
			},
			// 动态获取swiper-item的高度
			getHeight(){
				uni.createSelectorQuery()
				.select('#start'+this.current).boundingClientRect()
				.select('#end'+this.current).boundingClientRect()
				.exec(date=>{
					console.log(date)
					if(date[0] == null){
						this.swiperHeight = 824		
					}else{
						this.swiperHeight = (date[1].top - date[0].top) * 2
					}	
				})
			},
			// 获取救援类型
			getRescueTypeList(){
				this.$request({
					url: 'cfuser/rescue/type/list',
					method: 'GET',
					success:(res)=>{
						console.log("res:"+res)
						this.serviceTag = res.data.rows
					}
				})
			},
			onReady(){
				this.getHeight()
			},
			onLoad(){
				this.loginUser = uni.getStorageSync("cfuser")
				this.getRescueTypeList()				
			},
			onShow(){
				if(this.position){
					uni.showToast({
						title: "订单超时",
						duration: 2000,
						icon: 'none'
					});
				}
			}
		}
	}
</script>

<style scoped>
	page {
		padding: 0 20rpx;
	}
	.background {
		width: 750rpx; 
		height: 280rpx;
		background-color: #2979ff;
	}
	/* #ifndef MP-WEIXIN */
	.background {
		margin-left: -20rpx;
	}
	/* #endif */
	.map {
		width: 670rpx;
		height: 380rpx;
		padding: 20rpx 20rpx;
		margin-top: 20rpx;
		border-radius: 20rpx;
		background-color: white;
		position: absolute;
		top: 0;
	}
	
	/* #ifdef MP-WEIXIN */
	.map {
		margin-left: 20rpx;
	}
	/* #endif */
	
	.service {
		margin-top: 180rpx;
		width: 670rpx;
		border-radius: 20rpx;
		background-color: white;
		padding: 20rpx 20rpx;
	}
	
	/* #ifdef MP-WEIXIN */
	.service {
		margin-left: 20rpx;
	}
	/* #endif */
	
	.service > .serviceTag {
		display: flex;
		justify-content: space-between;
	}
	.serviceTag > .tagItem {
		width: 80rpx;
		padding: 6rpx 0;
		text-align: center;
	}
// 蓝色下边框
	.choice{
		border-bottom: 4rpx solid #2979ff;
	}
	.hoverClass {
		border-bottom: 4rpx solid #2979ff;
	}

	.input {
		display: flex;
		align-items: center;
		margin-top: 30rpx;
	}
	.input > .tag{
		background-color: #2979ff;
		color: white;
		font-size: 20rpx;
		width: 120rpx;
		padding: 10rpx;
		text-align: center;
		vertical-align: middle;
		border-radius: 50rpx;
	}
	.input > input {
		border: 2rpx solid #e9e9eb;
		margin-left: 10rpx;
		padding-left: 30rpx;
		border-radius: 90rpx;
		width: 500rpx;
		height: 60rpx;
		font-size: 20rpx;
	}
	.picker {
		border: 2rpx solid #e9e9eb;
		margin-left: 10rpx;
		padding-left: 30rpx;
		width: 480rpx;
		height: 60rpx;
		line-height: 60rpx;
		border-radius: 90rpx;
		color: #6a6a6a;
	}
	.input > .textarea{
		border: 2rpx solid #e9e9eb;
		border-radius: 20rpx;
		margin-left: 10rpx;
		padding: 30rpx;
		width: 500rpx;
		height: 150rpx;
		font-size: 20rpx;
	}
	.form .btn{
		width: 500rpx;
		margin-top: 50rpx;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 30rpx;
		color: white;
		background-image: linear-gradient(to right, #FF7438, #FF4000);
	}
	.form .ToRecord{
		font-size: 22rpx;
		color: gray;
		margin-top: 30rpx;
		width: 116rpx;
		position: relative;
		left: 50%;
		transform: translateX(-50%);
	}
	.form .ToRecord > .arrow{
		border-top: 2rpx solid gray;
		border-right: 2rpx solid gray;
		width: 14rpx;
		height: 14rpx;
		top: 50%;
		transform: translateY(-50%) rotate(45deg);
		right: 0rpx;
		position: absolute;
	}
	
// 警务救助样式
	.Policeervice{
		background-color: white;
		margin-top: 20rpx;
		padding: 0 20rpx;
		padding-bottom: 40rpx;
		border-radius: 20rpx;
	}
	
	/* #ifdef MP-WEIXIN */
	.Policeervice {
		width: 670rpx;
		margin-left: 20rpx;
	}
	/* #endif */
	
	.Policeervice > .title{
		font-size: 36rpx;
		height: 100rpx;
		line-height: 100rpx;
	}
	
	.Policeervice > .body{
		display: flex;
		justify-content: space-between;
	}
	.body > view {
		text-align: center;
	}
	.body .icon{
		width: 60rpx;
		height: 60rpx;
	}
	.body > view > view:nth-child(2){
		margin-top: 14rpx;
	}
</style>
